﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BusinessPlatformTool.Enumerator;

namespace BusinessPlatformTool
{
    class ConvertEx
    {
        public static System.Data.DbType ToSystemType(DbType dbType)
        {
            System.Data.DbType dbtype = default(System.Data.DbType);
            switch (dbType)
            {
                case DbType.Smallint:
                    dbtype = System.Data.DbType.Int16;
                    break;
                case DbType.Int:
                    dbtype = System.Data.DbType.Int32;
                    break;
                case DbType.Bigint:
                    dbtype = System.Data.DbType.Int64;
                    break;
                case DbType.Numeric:
                case DbType.Decimal:
                case DbType.Smallmoney:
                case DbType.Money:
                    dbtype = System.Data.DbType.Decimal;
                    break;
                case DbType.Char:
                case DbType.Varchar:
                case DbType.Nvarchar:
                case DbType.Text:
                case DbType.Ntext:
                    dbtype = System.Data.DbType.String;
                    break;
                case DbType.Datetime:
                case DbType.Smalldatetime:
                    dbtype = System.Data.DbType.DateTime;
                    break;
                case DbType.Bit:
                    dbtype = System.Data.DbType.Boolean;
                    break;
                case DbType.Tinyint:
                    dbtype = System.Data.DbType.Byte;
                    break;
                case DbType.Float:
                    dbtype = System.Data.DbType.Double;
                    break;
                case DbType.Real:
                    dbtype = System.Data.DbType.Single;
                    break;
                case DbType.Date:
                    dbtype = System.Data.DbType.Date;
                    break;
                case DbType.Datetimeoffset:
                    dbtype = System.Data.DbType.DateTimeOffset;
                    break;
                case DbType.Datetime2:
                    dbtype = System.Data.DbType.DateTime2;
                    break;
                case DbType.Time:
                    dbtype = System.Data.DbType.Time;
                    break;
                case DbType.Nchar:
                    dbtype = System.Data.DbType.StringFixedLength;
                    break;
                case DbType.Binary:
                case DbType.Varbinary:
                case DbType.Image:
                case DbType.Timestamp:
                    dbtype = System.Data.DbType.Binary;
                    break;
                case DbType.Uniqueidentifier:
                    dbtype = System.Data.DbType.Guid;
                    break;
                case DbType.Sql_variant:
                    dbtype = System.Data.DbType.Object;
                    break;
                case DbType.Xml:
                    dbtype = System.Data.DbType.Xml;
                    break;
                default:
                    dbtype = default(System.Data.DbType);
                    break;
                //case DbType.Hierarchyid:dbtype = System.Data.DbType. break;
                //case DbType.Cursor:dbtype = System.Data.DbType. break;
                //case DbType.Table:dbtype = System.Data.DbType. break;
            }
            return dbtype;
        }
    }
}
